import { getGwfb, getRyzs, getSlfb, getYgbmfb } from '@/services/Organization/zzjgfxService';

export default {
    namespace: 'zzjgfx',
    state: {
        ryzs: {
            desc: '',
            list: []
        },
        ygbmfb: [],
        ygjsfb: [],
        slfb: [],
        gwfb: [],
        bmfbIndex: 0
    },
    effects: {
        *fetchAllData({ payload }, { put, all }) {
            const { organizationCode } = payload;
            yield all([
                put({
                    type: 'fetchYgbmfb',
                    payload
                }),
                put({
                    type: 'fetchSlfb',
                    payload: {
                        organizationCode
                    }
                }),
                put({
                    type: 'fetchGwfb',
                    payload: {
                        organizationCode
                    }
                })
            ]);
        },
        *fetchRyzs({ payload }, { call, put }) {
            const result = yield call(getRyzs, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        ryzs: result.data
                    }
                });
            }
        },
        *fetchYgbmfb({ payload }, { call, put }) {
            const result = yield call(getYgbmfb, payload);

            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        ygbmfb: result.data
                    }
                });
            }
        },
        *fetchSlfb({ payload }, { call, put }) {
            const result = yield call(getSlfb, payload);

            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        slfb: result.data
                    }
                });
            }
        },
        *fetchGwfb({ payload }, { call, put }) {
            const result = yield call(getGwfb, payload);
            console.log('===============================================>result', result);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        gwfb: result.data
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
